{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    {include file="form" /}
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            {tp:menu menu="delete,recyclebin" /}
                        <a class="btn btn-primary radius mr-5" id="xuan" style=""  href="javascript:;" onclick="xuan()">excel导出</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l" id="ck" style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-width: 500px;display: none">
        </span>
    </div>
    <div id="test">
        {include file="ajaxpage"}
    </div>

</div>
{/block}

{block name='script'}
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script>
    function fen() {
        layer.msg('该派单的旅客已分配住宿');
    }
    //无刷新分页
    $(document).on('click','.pagination a',function (event) {
        var url = $(this).attr('href');
        $.ajax({
            type: 'get',
            url: url,
            success: function (data) {
                $('#test').empty();
                $('#test').html(data)
            }
        });
        return false;
    });

    //全选
    function checkAlls(e) {
        this.checked = $(e).is(':checked')
        $("#ck").css('display','inline')
        var ck_temp =  $("input:checked[name='id[]']");
        console.log('ck_temp',ck_temp)
        $("input[name='id[]']").prop("checked",this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked;
        console.log('allChecked',allChecked)
        console.log('sonChecked',sonChecked)
        if (sonChecked && allChecked){
            var ck_arr = $("#ck").children();
            // $('#xuan').css('display','inline'); // 显示选择excel导出数据
            // $('#sou').css('display','none') ;// 隐藏部分或全部excel导出数据

            var radioData =  $("input:checked[name='id[]']");
            var ck = radioData.serializeArray();
            console.log('ck',ck)
            var len = ck.length;
            for(var i=0;i<len;i++){
                var temp_to_ck = "#"+ck[i]['value']
                if($(temp_to_ck).length ==0){
                    $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" style="padding: 2px 6px;margin: 2px" id='+ck[i]['value']+'>'+ck[i]['value']+'</span>')
                }

            }
            ck.push({name: 'search',value: 'all'})
        }else{
            var len_ck = ck_temp.length;
            for(var y = 0;y < len_ck; y++){
                var temp_id = "#"+ck_temp[y]['value'];
                $(temp_id).remove()
            }
            // $('#xuan').css('display','none');
            // $('#sou').css('display','inline')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    }
    //单选
    function single(e) {
        $("#ck").css('display','inline')
        var ck = $(e).is(':checked')
        if(ck){
            var checked_len = $("input:checkbox:checked").length;
            var list_len = $("input[name='id[]']").length;
            if(list_len == checked_len){
                $('#checkAlls').prop('checked',true);
            }
            console.log('checked_len',checked_len)
            console.log('list_len',list_len)
            var val = $(e).val()
            $(e).prop('checked',true)
            $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" id='+val+' style="padding: 2px 6px;margin: 2px">'+val+'</span>');
        }else{
            $('#checkAlls').prop('checked',false);
            var temp_id = "#"+$(e).val()
            $(temp_id).remove();
            $(e).attr('checked',false)
        }
    }

    function xuan() {
        var ck_arr = $("#ck").children();
        var ck_len = ck_arr.length
        var dataArr = new Array
        if(ck_len<=0){
            layer.msg('请进行勾选！', {
                time: 2000,
            });
            return true;
        }else{
            for(var i = 0;i < ck_len;i++){
                // dataArr.push({value:ck_arr[i].innerText})
                dataArr.push(ck_arr[i].innerText)
            }
            console.log('date',dataArr);
            $.ajax({
                type: 'post',
                url: '/admin/portion_traveler/get_excel',
                data: {ids:dataArr},
                success: function (res) {
                    if (res.code == 5){
                        // console.log('data', res);
                        location.href = res.msg; // 下载文件
                        // 删除文件
                        unclinkFile(res.msg)
                        layer.msg('导出数据成功');
                    } else {
                        layer_open('excel导出数据','/admin/pub/role/id/1')
                    }
                }
            });
        }
    }
    function cancel(e) {
        var temp_id = "#"+$(e).attr('id')
        var temp_id_2 = "#ck_"+$(e).attr('id')
        $(temp_id_2).prop("checked",false);
        $(temp_id).remove();
    }
</script>
{/block}

